<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="mini" label-width="68px">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="商品编号" prop="commodityNo">
            <el-input v-model="queryParams.commodityNo" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="商品名称" prop="commodityName">
            <el-input v-model="queryParams.commodityName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermi="['cld:materialstatistics:export']" icon="el-icon-download" plain size="mini" type="primary"
                   @click="handleExport('备货统计')">导出备货统计
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="商品编号" align="center" prop="commodityNo" />
      <el-table-column label="商品名称" align="center" prop="commodityName" />
      <el-table-column label="商品单价" align="center" prop="commodityPrice" >
        <template slot-scope="scope">
          {{toMoney(scope.row.commodityPrice)}}
        </template>
      </el-table-column>
      <el-table-column label="商品单位" align="center" prop="commodityUnit" />
      <el-table-column label="商品规格" align="center" prop="commoditySpec" />
      <el-table-column label="库存总量" align="center" prop="stockNumber" />
      <el-table-column label="需求数量" align="center" prop="appNumber" />
      <el-table-column label="采购数量" align="center" prop="purchaseNumber" />
      <el-table-column label="采购金额" align="center" prop="purchasePrice" >
        <template slot-scope="scope">
          {{toMoney(scope.row.purchasePrice)}}
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { stockAppDetails } from '@/api/cld/materialStatistics'
export default {
  name: "stockAppDetails",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        commodityNo: null,
        commodityName: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      stockAppDetails(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //备货统计导出
    handleExport(fileName) {
      this.download('cld/materialStatistics/exportStockAppDetails', {}, `${fileName}.xlsx`)
    }
  }
};
</script>
